<?php
/*********************************************************************\
*  Copyright (c) 1998-2013, TH. All Rights Reserved.
*  Author :wuyou
*  FName  :Client.php
*  Time   :2017/07/27 17:02:55
*  Remark :客户档案管理
\*********************************************************************/
FLEA::loadClass('TMIS_Controller');
class Controller_Jichu_Client extends TMIS_Controller {
    var $_modelExample;
    var $_modelEmploy;
    var $title = "客户档案";
    var $funcId = '90-5';

    function __construct() {
        $this->_modelExample = FLEA::getSingleton('Model_Jichu_Client');
        $this->_modelEmploy = FLEA::getSingleton('Model_Jichu_Employ');
    }

    /**
     * 角色html配置form
     * Time：2018/12/13 15:49:40
     * @author li
     * @param 参数类型
     * @return 返回值类型
    */
    public function buildHtml() {
        $params = array();
        $params['formItems'] = array(
            array(
                'type'      =>'comp-text',
                'name'      =>'compCode',
                'title'     =>'客户代码',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'compName',
                'title'     =>'客户名称',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-select',
                'name'      =>'traderId',
                'title'     =>'公司员工',
                'filterable'=>true,
                'clearable' =>true,
                'value'     =>'',
                'options'   =>$this->_modelEmploy->getSelect(true),
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'people',
                'title'     =>'客户联系人',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'mobile',
                'title'     =>'手机',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'tel',
                'title'     =>'电话',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'address',
                'title'     =>'地址',
                'clearable' =>true,
                'value'     =>'',
            ),
            // array(
            //     'type'      =>'comp-text',
            //     'name'      =>'zipCode',
            //     'title'     =>'邮编',
            //     'clearable' =>true,
            //     'value'     =>'',
            // ),
            array(
                'type'      =>'comp-text',
                'name'      =>'fax',
                'title'     =>'传真',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'email',
                'title'     =>'E-mail',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'bank',
                'title'     =>'开户银行',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'accountId',
                'title'     =>'账号',
                'clearable' =>true,
                'value'     =>'',
            ),
            array(
                'type'      =>'comp-text',
                'name'      =>'taxId',
                'title'     =>'税号',
                'clearable' =>true,
                'value'     =>'',
            ),
            // array(
            //     'type'      =>'comp-text',
            //     'name'      =>'qianzheng',
            //     'title'     =>'委托人签证',
            //     'clearable' =>true,
            //     'value'     =>'',
            //     'append'    =>'主管单位委托人签证'
            // ),
            array(
                'type'      =>'comp-textarea',
                'name'      =>'memo',
                'title'     =>'备注',
                'clearable' =>true,
                'value'     =>'',
            ),
        );

        $params['rules'] = array(
            'compName'=>array(
                array(
                    'required'=>true,
                    'message'=>'客户名称必须',
                )
            ),
            'traderId'=>array(
                array(
                    'required'=>true,
                    'message'=>'公司员工必须',
                )
            ),
        );

        return $params;
    }

    /**
     * @desc ：客户信息编辑
     * Time：2017/07/31 15:26:15
     * @author Wuyou
    */
    function actionEdit(){
        $this->authCheck($this->funcId);
        $row = $this->_modelExample->find($_GET['id']);
        $row['dateEnter']=$row['dateEnter']=='0000-00-00'?'':$row['dateEnter'];
        $row['dateLeave']=$row['dateLeave']=='0000-00-00'?'':$row['dateLeave'];

        $this->_edit($row);
    }

    /**
     * @desc ：新增客户档案
     * Time：2017/07/31 15:26:32
     * @author Wuyou
    */
    function actionAdd(){
        $this->authCheck($this->funcId);
        $this->_edit();
    }

    function _edit($Arr){
        $formParams = $this->buildHtml();

        if(!$Arr){
            foreach ($formParams['formItems'] as $key => $v) {
                $Arr[$v['name']] = $v['value'].'';
            }
        }

        // dump($Arr);exit;

        $smarty = & $this->_getView();

        $smarty->assign('formItems',$formParams['formItems']);
        $smarty->assign('rules',$formParams['rules']);
        $smarty->assign('title','基本信息');
        $smarty->assign('row',$Arr);
        $smarty->assign('action',$this->_url('Save'));
        $smarty->display('MainForm.tpl');
    }

    /**
     * @desc ：部门档案查询
     * Time：2017/07/31 15:33:05
     * @author li
    */
    function actionRight() {
        $this->authCheck($this->funcId);

        $searchItems = array(
            'compName'   =>'',
            'traderId'   =>'',
        );
        $smarty = & $this->_getView();
        $arrFieldInfo = array(
            'compCode'        =>array('text'=>'客户代码','width'=>''),
            'compName'        =>array('text'=>'客户名称','width'=>'240','forKeySearch'=>true,),
            // 'compFullName' =>array('text'=>'客户名称(全)','width'=>''),
            'employName'      =>array('text'=>'业务员','width'=>''),
            'people'        =>array('text'=>'联系人','width'=>''),
            'mobile'          =>array('text'=>'手机','width'=>''),
            'tel'             =>array('text'=>'电话','width'=>''),
            /*'image'         =>array(
            'text'            =>'名片',
            'width'           =>'',
            'isHtml'          =>'component',
            'componentType'   =>'tip-card-image'
            ),*/
            'email'           =>array('text'=>'e-mail','width'=>''),
            'address'         =>array('text'=>'地址','width'=>''),
            // 'qianzheng'       =>array('text'=>'主管单位委托人签证','width'=>''),
            'memo'            =>array('text'=>'备注','width'=>''),
        );

        $smarty->assign('title', '客户列表');
        $smarty->assign('arr_field_info', $arrFieldInfo);
        $smarty->assign('action', $this->_url('GetRows'));
        $smarty->assign('searchItems', $searchItems);
        // $smarty->assign('colsForKey', array(
        //         array('text' =>'关键字','col'=>'key')
        // ));

        $smarty->assign('editButtons',array(
            array('text'=>'编辑','type'=>'redirect','icon'=>'el-icon-edit','options'=>array(
                //点击后跳转的地址
                'url'            =>$this->_url('Edit').'&id={id}',
                'disabledColumn' =>'__disabledEdit',
            )),
            array('text'=>'删除','type'=>'remove','options'=>array(
                'url'            =>$this->_url('RemoveAjax'),
                'disabledColumn' =>'__disabledRemove',
            )),
        ));

        $rightMenu = array(
            array('text'=>'导入客户Excel','url'=>$this->_url('ImportFile'),'icon'=>'el-icon-folder-checked'),
        );
        $smarty->assign('menuRightTop', $rightMenu);

        $smarty->assign('addUrl',$this->_url('Add'));
        $smarty->assign('sonTpl','Jichu/ClientTable.js');
        $smarty->display('TableList.tpl');
    }

    /**
     * 获取计划任务的数据
     * @author li
    */
    public function actionGetRows()
    {
        $auth = $this->authCheck(0 ,true);

        if(!$auth){
            $ret = array(
              'total'   =>0,
              'columns' =>array(),
              'rows'    =>array(),
            );
            echo json_encode($ret);exit;
        }

        $requestParam = file_get_contents('php://input');
        $_POST = json_decode($requestParam,true);

        $pagesize    = $_POST['pagesize'];
        $currentPage = $_POST['currentPage'];

        //处理搜搜
        $keyField    = isset($_POST['colForKey']) ? $_POST['colForKey'] : 'key';
        $post[$keyField] = $_POST['key'];
        if($keyField!='key') $_POST['key'] = '';

        $arr = $_POST;

        $condition = array();

        //得到当前用户的关联业务员
        $mUser = FLEA::getSingleton('Model_Acm_User');
        $traderArr = $mUser->getTraderIdByUser($_SESSION['USERID']);

        if($traderArr['_ALL_'] == false){
            $condition['in()'] = array('traderId'=>$traderArr['Traders']);
        }

        if($arr['compName']!='') {
            // $condition[] = array('compCode',"%{$arr['key']}%",'like','or');
            $condition[] = array('compName',"%{$arr['compName']}%",'like');
        }

        if($arr['traderId']!=0) {
            $condition[] = array('traderId',"{$arr['traderId']}",'=');
        }

        // dump($sql);exit;
        FLEA::loadClass('TMIS_Pager');
        $pager = & new TMIS_Pager($this->_modelExample,$condition,'id desc',$pagesize ,($currentPage - 1));
        $rowset = $pager->findAll();
        // dump($rowset);exit;
        foreach($rowset as & $v){
            $v['compDate'] = $v['compDate']=='0000-00-00' ? '' : $v['compDate'];

            //查找业务员姓名
            if($v['traderId']){
                $traderInfo = $this->_modelEmploy->find($v['traderId']);
                $v['employName'] = $traderInfo['employName'];
            }

            //名片信息
            if($v['imageId']){
                $v['imageSrc'] = $this->getImagePath($v['imageId']);
            }
        }

        $ret = array(
          'total'   =>$pager->totalCount,
          'columns' =>array(),
          'rows'    =>$rowset,
        );
        echo json_encode($ret);exit;
    }


    /**
     * @desc ：客户档案保存
     * Time：2017/07/31 15:29:19
     * @author Wuyou
    */
    function actionSave() {
        $auth = $this->authCheck($this->funcId ,true);

        if(!$auth){
            $ret = array('msg'=>'没有登陆或编辑权限','success'=>false);
            echo json_encode($ret);exit;
        }
        //post参数
        $post = $this->axiosPost();

        if(empty($post['id'])) {
            $condition = array();
            $condition[] = array('compName',$post['compName'],'=');
            $count = $this->_modelExample->findCount($condition);

            if($count > 0) {
                $ret = array('msg'=>'公司名称重复','success'=>false);
                echo json_encode($ret);exit;
            }
        } else {
            //修改时判断是否重复
            $condition = array();
            $condition[] = array('compName',$post['compName'],'=');
            $condition[] = array('id',$post['id'],'<>');
            $count = $this->_modelExample->findCount($condition);

            if($count > 0) {
                $ret = array('msg'=>'公司名称重复','success'=>false);
                echo json_encode($ret);exit;
            }
        }

        //数据保存
        $result = $this->_modelExample->save($post);
        if($result){
            $ret = array(
                'success' =>true,
                'msg'     =>'操作成功',
                'targetUrl' =>$this->_url('Right'),
            );
        }else{
            $ret = array(
                'success' =>false,
                'msg'     =>'操作失败',
            );
        }

        echo json_encode($ret);exit;

    }

    /**
     * @desc ：客户档案删除 存在报价和订单的客户不允许删除
     * Time：2017/07/31 15:30:14
     * @author Wuyou
    */
    function actionRemove() {
        // 删除验证
        if($_GET['id']!="") {
            $sql="SELECT count(*) as cnt FROM `trade_order` where clientId=".$_GET['id'];
            $re=$this->_modelExample->findBySql($sql);
            //dump($re);exit;
            if($re[0]['cnt']>0) {
                js_alert('此客户有订单记录存在，不允许删除',null,$this->_url('Right'));
            }
        }
        parent::actionRemove();
    }

    /**
     * @desc ：员工档案删除 验证是否已经被使用
     * Time：2017/07/31 15:49:06
     * @author lwj
    */
    function actionRemoveAjax() {
        $post = $this->axiosPost();
        $id = intval($post['row']['id']);

        //查找是否已经被使用
        $array = array(
            'Model_Sample_Chuku' => 'clientId',
        );

        $isOccupy = false;

        foreach ($array as $key =>  & $v) {
            $tmpModel = FLEA::getSingleton($key);
            $condition = array();
            $condition[$v] = $id;
            $count = $tmpModel->findCount($condition);

            //如果某个表中存在，则不能删除
            if($count > 0){
                $isOccupy = true;
                $msg = $tmpModel->moduleName;
                break;
            }
        }

        if($isOccupy){
            $ret = array(
                'success' =>false,
                'msg'     =>'被'.$msg.'使用，禁止删除',
            );
            echo json_encode($ret);exit;
        }


        $res = $this->_modelExample->removeByPkv($id);

        if($res){
            $ret = array(
                'success' =>true,
                'msg'     =>'删除成功',
            );
        }else{
            $ret = array(
                'success' =>false,
                'msg'     =>'删除失败',
            );
        }
        echo json_encode($ret);exit;
    }

    /**
     * 导入excel中的客户新，使用的是csv文件
     * Time：2019/10/30 13:47:43
     * @author li
     * @param 参数类型
     * @return 返回值类型
    */
    function actionImportFile(){
        $formParams = $this->buildHtmlImportantFile();
        $arr = array();
        foreach ($formParams['formItems'] as & $v) {
            $arr[$v['name']] = $v['value'];
        }

        // dump($arr);exit;

        $smarty = & $this->_getView();
        $smarty->assign('formItems',$formParams['formItems']);
        $smarty->assign('rules',$formParams['rules']);
        $smarty->assign('title','基本信息');
        $smarty->assign('row',$arr);
        $smarty->assign('action',$this->_url('ConfirmData'));
        $smarty->display('MainForm.tpl');
    }

    /**
     * 角色html配置form
     * Time：2018/12/13 15:49:40
     * @author li
     * @param 参数类型
     * @return 返回值类型
    */
    public function buildHtmlImportantFile() {
        $params = array();
        $params['formItems'] = array(
            array(
                'type'      =>'comp-text',
                'name'      =>'template',
                'title'     =>'1.模版下载',
                'readonly'  =>true,
                'value'     =>'请先下载模版并整理好待上传的数据',
                'append'    =>'<a href="Resource/Moban/jichu_client.csv" download="客户列表模版.csv" title="csv模版下载">csv模版下载</a>',
            ),
            array(
                'type'       =>'comp-file',
                'name'       =>'filePath',
                'title'      =>'2.上传csv',
                'buttonText' =>'开始上传附件',
                'action'     =>$this->_url('ImportFileData'),//上传地址
                'accept'     =>'.csv',//接受上传的文件类型
                'limit'      =>1,//最大允许上传个数
                'value'      =>'',
            ),
        );

        $params['rules'] = array(

        );

        return $params;
    }

    /**
     * 接收文档
     * Time：2019/10/30 14:37:53
     * @author li
     * @param 参数类型
     * @return 返回值类型
    */
    function actionImportFileData(){
        $file = $_FILES['filePath'];
        $pathinfo = pathinfo($file['name']);
        // dump($pathinfo);
        if(strtolower($pathinfo['extension']) != 'csv'){
            $ret = array('msg'=>'文件类型必须为CSV文件','success'=>false);
            echo json_encode($ret);exit;
        }

        $path = "upload/files/";
        $tmpname = $path.uniqid().rand(10000,99999).'.'.strtolower($pathinfo['extension']);
        move_uploaded_file($file['tmp_name'] ,$tmpname);

        $ret = array('msg'=>'完成上传','success'=>true,'filePath'=>$tmpname);
        echo json_encode($ret);exit;
    }

    /**
     * 确认数据
     * Time：2019/10/30 15:09:44
     * @author li
     * @param 参数类型
     * @return 返回值类型
    */
    function actionConfirmData(){
        $post = $this->axiosPost();
        // dump($post);
        if(!$post['filePath']){
            $ret = array('msg'=>'还没有上传文件','success'=>false);
            echo json_encode($ret);exit;
        }

        //开始上传数据
        $msg = array();
        foreach ($post['filePath'] as & $v) {
            if(!$v['url'] || !file_exists($v['url'])){
                continue;
            }
            //开始逐行读取数据
            $tmp = $this->readFileByLine($v['url']);
            $msg = array_merge($msg ,$tmp);
        }

        $ret = array('msg'=>join('<br/>',$msg),'success'=>true);
        echo json_encode($ret);exit;

    }

    /**
   * 按行读取文件
   * @param string $filename
   */
  function readFileByLine($filename){
      $fh = fopen($filename, 'r');
      $data = array();
      $i = 0;
      $success = 0;
      $fail = 0;
      $msg = array();

      while (! feof($fh)) {
          $line = fgets($fh);
          if($line){
            $i++;
            if($i == 1) continue;
            $tmp = explode(',', $line);
            $data = array(
              'compCode'   => trim(iconv('GB2312', 'UTF-8', $tmp[0])) ,
              'compName'   => trim(iconv('GB2312', 'UTF-8', $tmp[1])),
              'people'     => trim(iconv('GB2312', 'UTF-8', $tmp[2])),
              'tel'        => trim(iconv('GB2312', 'UTF-8', $tmp[3])),
              'mobile'     => trim(iconv('GB2312', 'UTF-8', $tmp[4])),
              'address'    => trim(iconv('GB2312', 'UTF-8', $tmp[5])),
              'fax'        => trim(iconv('GB2312', 'UTF-8', $tmp[6])),
              'email'      => trim(iconv('GB2312', 'UTF-8', $tmp[7])),
              'bank'       => trim(iconv('GB2312', 'UTF-8', $tmp[8])),
              'accountId'  => trim(iconv('GB2312', 'UTF-8', $tmp[9])),
              'taxId'      => trim(iconv('GB2312', 'UTF-8', $tmp[10])),
              'memo'       => trim(iconv('GB2312', 'UTF-8', $tmp[11])),
              'employName' => trim(iconv('GB2312', 'UTF-8', $tmp[12]))
            );

            $t = array_filter($data);
            if($t['compCode'] && $t['compName']){
              //判断是否重复了
              $isHave = $this->_modelExample->findCount(array('compCode'=>$data['compCode']));
              if($isHave){
                $fail++;
                $msg[] = $data['compCode']."已经存在，导入失败<br/>";
              }else{
                //开始导入数据
                //先确认业务员是否存在，业务部是否存在
                if($data['employName']){
                    $tmp = $this->_modelEmploy->find(array('employName'=>trim($data['employName'])));
                    if($tmp){
                        $data['traderId'] = $tmp['id'];
                    }else{
                        //确保业务部门是否存在
                        if(!$this->_departmentTraderId){
                            $sql="SELECT * from jichu_department where depName like '%销售%' or depName like '%业务%' limit 0,1";
                            $tmp = $this->_modelExample->findBySql($sql);
                            if($tmp){
                                $this->_departmentTraderId = $tmp[0]['id'];
                            }else{
                                $_modelDep = FLEA::getSingleton('Model_Jichu_Department');
                                $this->_departmentTraderId = $_modelDep->save(array('depName'=>'销售部'));
                            }
                        }

                        //开始保存员工信息到表里
                        $employData = array(
                            'employName' =>$data['employName'],
                            'depId'      =>$this->_departmentTraderId,
                        );
                        $eid = $this->_modelEmploy->save($employData);
                        $data['traderId'] = $eid;
                    }
                }

                $id = $this->_modelExample->save($data);
                if($id > 0){
                  $success++;
                }else{
                  $fail++;
                  $msg[] =  $data['compCode']."导入失败<br/>";
                }
              }
            }else{
              $fail++;
              $msg[] =   "第{$i}行导入失败，无客户编号或者客户名称<br/>";
            }

          }
      }

      fclose($fh);
      $msg[] =   "导入产品".($i-1)."条，成功{$success}，失败{$fail}<br/>";

      return $msg;
  }

    /**
     * @desc ：在模式对话框中显示待选择的客户，返回某个客户的json对象
     * Time：2017/07/31 15:31:55
     * @author Wuyou
    */
    // function actionPopup() {
    //     FLEA::loadClass('TMIS_Pager');
    //     $arr = TMIS_Pager::getParamArray(array(
    //         'clientCode'=>'',
    //         'clientName' => '',
    //     ));
    //     //业务员只能看自己的客户
    //     $mUser = & FLEA::getSingleton('Model_Acm_User');
    //     //如果不能看所有订单，得到当前用户的关联业务员
    //     $traderArr = $mUser->getTraderIdByUser($_SESSION['USERID']);

    //     $condition=array();

    //     if($traderArr['_ALL_'] == false){
    //         $condition['in()'] = array('traderId'=>$traderArr['Traders']);
    //     }

    //     if($arr['clientCode']!='') {
    //         $condition[] = array('compCode',"%{$arr['clientCode']}%",'like');
    //     }

    //     if($arr['clientName']!='') {
    //         $condition[] = array('compName',"%{$arr['clientName']}%",'like');
    //     }

    //     // dump($condition);die;
    //     $pager = new TMIS_Pager($this->_modelExample,$condition,'id asc'); //id asc 不能改变 改变则有问题 记录
    //     $rowset =$pager->findAll();

    //     if(count($rowset)>0) foreach($rowset as & $v){
    //         $str="select * from jichu_employ where id='{$v['traderId']}'";
    //         $re=mysql_fetch_assoc(mysql_query($str));
    //         $v['traderName']=$re['employName'];
    //         if($re['isFire']==1){
    //             $v['fire']='是';
    //         }
    //     }
    //     $arr_field_info = array(
    //          'compCode'          =>'客户代码',
    //          'Trader.employName' =>'业务员',
    //          'address'           =>'地址',
    //          'people'          =>'联系人',
    //          'dianhua'           =>'固定电话',
    //          'mobile'            =>'手机',
    //          'email'             =>'e-mail',
    //          'zipCode'           =>'邮编',
    //          'payAccount'        =>'到付帐号',
    //          'billingData'       =>'开票资料',
    //          'memo'              =>'备注',
    //     );

    //     $smarty = & $this->_getView();
    //     $smarty->assign('title', '选择客户');
    //     $pk = $this->_modelExample->primaryKey;
    //     $smarty->assign('pk', $pk);
    //     $smarty->assign('add_display','none');
    //     $smarty->assign('arr_field_info',$arr_field_info);
    //     $smarty->assign('arr_field_value',$rowset);
    //     $smarty->assign('add_url',$this->_url('add',array('fromAction'=>$_GET['action'])));
    //     $smarty->assign('s',$arr);
    //     $smarty->assign('page_info',$pager->getNavBar($this->_url($_GET['action'],$arr)));
    //     $smarty->assign('arr_condition',$arr);
    //     $smarty->assign('clean',true);
    //     $smarty-> display('Popup/CommonNew.tpl');
    // }

    // function actionGetJsonByKey() {
    //     $sql = "select * from jichu_client where (
    //         compName like '%{$_GET['code']}%' or zhujiCode like '%{$_GET['code']}%' or compCode like '%{$_GET['code']}%'
    //     )";
    //     $arr = $this->_modelExample->findBySql($sql);
    //     echo json_encode($arr);exit;
    // }
    //根据传入的id获得具体信息,订单录入时根据客户定位业务员时用到
    // function actionGetJsonById() {
    //     $sql = "select * from jichu_client where id='{$_GET['id']}'";
    //     $arr = $this->_modelExample->findBySql($sql);
    //     echo json_encode($arr[0]);exit;
    // }
    //根据业务员查找客户
    // function actionGetJsonByTraderId() {
    //     $sql = "select * from jichu_client where 1";
    //     if($_GET['traderId']!='')$sql.=" and traderId='{$_GET['traderId']}'";
    //     $mUser = & FLEA::getSingleton('Model_Acm_User');
    //     // $canSeeAllOrder = $mUser->canSeeAllOrder($_SESSION['USERID']);
    //     /*if(!$canSeeAllOrder) {
    //         //如果不能看所有订单，得到当前用户的关联业务员
    //         $traderId = $mUser->getTraderIdByUser($_SESSION['USERID']);
    //         if($traderId)$sql .= " and traderId in ({$traderId})";
    //     }*/

    //     $traderArr = $mUser->getTraderIdByUser($_SESSION['USERID']);
    //     if($traderArr['_ALL_'] == false){
    //         $traderId = join(',',$traderArr['Traders']);
    //         !$traderId && $traderId = '-1';
    //         $sql .= " and traderId in ({$traderId})";
    //     }

    //     // $sql.=" order by convert(trim(compName) USING gbk)";
    //     // $arr = $this->_modelExample->findBySql($sql);
    //     $sql.=" order by ";
    //     $kg = & FLEA::getAppInf('khqcxs');
    //     if($kg)$sql.=" letters";
    //     else $sql.=" compCode";

    //     $arr = $this->_modelExample->findBySql($sql);

    //     //生成下拉框
    //     $ret=$this->_modelExample->options($arr);
    //     echo json_encode($ret);exit;
    // }

    // function actionSaveclientExport(){
    //     set_time_limit(0);
    //     $temp=array();$arr=array();
    //     foreach ($_FILES as $k=> &$v){
    //         for($i=0;$i<count($v['name']);$i++){
    //             foreach ($v as $key=> &$value){
    //                 $temp[$key]=$value;
    //             }
    //             $arr[][$k]=$temp;
    //         }
    //     }
    //     if($arr['0']['clientExport']['name']==''){
    //         js_alert("没有选择文件禁止保存",'window.history.go(-1)');
    //     }
    //     $path= 'upload/jichu/';
    //     foreach ($arr as &$v){
    //         $temp1='';
    //         foreach ($v as $kk=>&$vv){
    //             $temp1=$kk;
    //         }
    //         $dizhi['path']=$v[$kk];
    //         $filePath[$kk][]= $this->_importAttac($dizhi,$path);
    //     }
    //     $filePath=$filePath['clientExport']['0']['filePath'];
    //     // dump($filePath);die;
    //     $arr = $this->_readExcel($filePath,0);
    //     // dump($arr);die;
    //     foreach ($arr as $key => &$v) {
    //         if ($key <1) continue;
    //         // if(!$v[2]) continue;
    //         $_client = $this->_modelExample->find(array('compCode'=>trim((string)$v[3])));
    //         if($_client['id']) continue;
    //         $_employ = $this->_modelEmploy->find(array('employName'=>trim((string)$v[1])));
    //         $data=array(
    //             'id'=>'',
    //             'compName'=>trim((string)$v[2]),
    //             'compCode'=>trim((string)$v[3]),
    //             'traderId'=>trim((string)$_employ['id']),
    //             );
    //         $result=$this->_modelExample->save($data);
    //     }
    //     echo json_encode(array('success'=>true,'msg'=>'导入成功！'));exit;
    // }

}
?>